<?php

namespace mpend\modules\cms\models;

use Yii;

/**
 * 资讯模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class MatchArticleSearch extends ArticleSearch {

    /**
     * @inheritdoc
     */
    public function buildQuery($alias = 't') {
        $query = static::find();
        if ($alias) {
            $query->alias($alias);
            $alias .= '.';
        }
        $query->active(static::STATUS_ACTIVE);
        $query->innerJoinWith('channel channel');
        $query->andWhere([
            'channel.scope' => 'match',
        ]);
        $query->orderBy([
            $alias . 'recommend_id' => SORT_ASC,
            $alias . 'publish_at' => SORT_DESC,
            $alias . 'updated_at' => SORT_ASC,
        ]);
        $query->debug();
        return $query;
    }

    /**
     * 接口返回基础数据结构
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'title',
            'description',
            'format',
            'thumb' => 'thumbUrl',
            'body',
            'pictures',
        ];
    }

}
